
rm(list=ls())
pacman::p_load(ggthemes, tidyverse, haven, 
               readxl, estimatr, USAboundaries, 
               sf, interflex, sensemakr, psych, 
               sensemakr, devtools, USAboundaries)

rescale01 <- function(x){
  minx <- min(x, na.rm=T)
  maxx <- max(x, na.rm=T)
  return((x-minx)/(maxx - minx))
}

# Nationscape Replication Table C9 -----
ns <- read_dta('datasets/clean_ns_enviro_proj.dta')
lm1 <- lm_robust(gnd ~ sea_level_rise + # enact green new deal
                   pid7 + ideo5 + age + female + college + 
                   household_income + white,   ns, cluster=new_geoID)
texreg::texreg(list(lm1),
               custom.coef.names = c('Intercept','Susceptibility','Party ID (R)', 
                                     'Conservative', 'Age','Female','College',
                                     'Family Income','White'),
               custom.model.names = c('Support Green New Deal'),
               stars = c(0.1,0.05,0.01), include.ci=F,
               file = 'tables/appendix_ns_replication.tex')

# replication CES Table C10----
cces <- read_dta('datasets/cces2019.dta')
lm1 <- lm_robust(policy_scale ~ sea_level_rise + 
                   pid7 + ideo5 + age + male +
                   college + faminc_new + white,
                 cces, cluster=fips) 
lm2 <- lm_robust(pol1 ~ sea_level_rise + 
                   pid7 + ideo5 + age + male +
                   college + faminc_new + white,
                 cces, cluster=fips) 
lm3 <- lm_robust(pol2 ~ sea_level_rise + 
                   pid7 + ideo5 + age + male +
                   college + faminc_new + white,
                 cces, cluster=fips) 
lm4 <- lm_robust(pol3 ~ sea_level_rise + 
                   pid7 + ideo5 + age + male +
                   college + faminc_new + white,
                 cces, cluster=fips) 

# Table c10
texreg::texreg(list(lm1,lm2,lm3,lm4),
               custom.coef.names = c('Intercept','Susceptibility','Party ID (R)', 
                                     'Conservative', 'Age','Male','College',
                                     'Family Income','White'),
               custom.model.names = c('Policy Scale',
                                      'Reg Carbon','Renewables','EPA'),
               stars = c(0.1,0.05,0.01), include.ci=F,
               file = 'tables/appendix_cces_replication.tex')
